document.getElementById("login-btn").addEventListener("click", function() {
    let btn = this;
    btn.innerHTML = "登录中...";
    btn.disabled = true;
    
    // 获取用户输入的ID
    const userId = document.getElementById("UserId-login").value;
    // 获取用户输入的密码
    const password = document.getElementById("Password-login").value;
    
    fetch(`http://${_HOST_}:${_PORT_}/login`, {
        method: 'POST',
        headers: {
            'Content-Type': 'application/json'
        },
        body: JSON.stringify({
            userId,
            password
        })
    })
    .then(response => response.json())
    .then(data => {
        // 恢复按钮状态
        btn.disabled = false;
        btn.innerHTML = "登录！";
        
        if(data.code !== '0000'){
            btn.innerHTML = data.msg;
            return;
        }
        window.clickBtn.registerSuccess(data.userName, userId, data.userToken);
        window.clickBtn.openMainWindow();
    })
    .catch((err) => {
        btn.innerHTML = err.toString();
        btn.disabled = false;
    });
});